<template>
    <j-modal title="修改跟单员" :width="680" :visible="visible" :confirmLoading="confirmLoading" switchFullscreen
        @ok="handleSubmit" @cancel="handleCancel" cancelText="关闭">

        <a-spin :spinning="confirmLoading">
            <a-form>
                <a-form-item label="经销商" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    {{ model.name+model.companyCode }}
                </a-form-item>
                <a-form-item label="跟单员" :labelCol="labelCol" :wrapperCol="wrapperCol">
                    <a-select v-model="saleUserName" placeholder="请选择跟单员" allowClear  @change="changeSales">
                        <a-select-option v-for="s in merchandiserList" :key="s.value">{{ s.label }}</a-select-option>
                    </a-select>
                </a-form-item>
            </a-form>
        </a-spin>

    </j-modal>

</template>

<script type="text/ecmascript-6">
import { httpAction,getAction } from "@api/manage";

export default {
    name: "StmEditSales",
    data() {
        return {
            visible: false,
            confirmLoading: false,
            model: {},

            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            url: {
                updateStoreUser: 'system/sysStoreUser/updateStoreUser',
                getMerchandiserList: 'sys/user/getDropDownList',
            },
            saleUserName:'',
            realName:'',
            merchandiserList:[]
        }
    },
    created() {
        this.getMerchandiserList()
    },
    methods: {
        show(record) {
            this.visible = true;
            this.model = record;
            this.saleUserName = record.saleUserId;
            this.realName = record.saleRealName;
        },
        close() {
            this.$emit('close');
            this.visible = false;
        },
        /***获取跟单员列表 */
        getMerchandiserList() {
            getAction(this.url.getMerchandiserList, {}).then(res => {
                if (res.success) {
                    this.merchandiserList = res.result;
                } 
            })
        },
        changeSales(value, option){
            this.realName = this.merchandiserList.filter(x=>x.value == value)[0].label
        },
        handleSubmit() {
            if(!this.saleUserName){
                this.$message.warning('请选择跟单员');
                return;
            }
            httpAction(this.url.updateStoreUser, {storeId: this.model.storeId,userName:this.saleUserName,realName:this.realName}, "put").then((res) => {
                if (res.success) {
                    this.$message.success(res.message);
                    this.$emit('ok');
                } else {
                    this.$message.warning(res.message);
                }
            }).finally(() => {
                this.confirmLoading = false;
                this.close();
            });
        },
        handleCancel() {
            this.close()
        },
    }
}
</script>
<style lang="less" scoped>

</style>